package com.fallsvc.dayproblem.demo202511;

import java.util.HashMap;
import java.util.Map;

/**
 * @auther falls_vc
 * description:
 * @date 2025/11/20  23:49
 */

public class Demo20251120 {
    class Node {
    int val;
    Node next;
    Node random;

    public Node(int val) {
        this.val = val;
        this.next = null;
        this.random = null;
    }
}
//    https://leetcode.cn/problems/gas-station/description/?envType=study-plan-v2&envId=top-interview-150
//    加油站
    public int canCompleteCircuit(int[] gas, int[] cost) {

        int n = gas.length;
        int i = 0;
        while (i < n) {
            int sumOfGas = 0;
            int cnt = 0;
            while (cnt < n) {
                int j = (i + cnt) % n;
                sumOfGas += (gas[j]-cost[j]);

                if (sumOfGas < 0) {
                    break;
                }
                cnt++;
            }
            if (cnt == n) {
                return i;
            } else {
                i = i + cnt + 1;
            }
        }
        return -1;
    }

    //https://leetcode.cn/problems/copy-list-with-random-pointer/?envType=problem-list-v2&envId=hash-table
    // 随机链表复制

    public Node copyRandomList(Node head) {
        Map<Node,Node> map = new HashMap<>();
        Node cur = head;

        while(cur != null) {
            Node tmp= new Node(cur.val);
            map.put(cur,tmp);

            cur = cur.next;
        }

        cur = head;
        while(cur != null) {
            map.get(cur).next = map.get(cur.next);
            map.get(cur).random = map.get(cur.random);
            cur = cur.next;
        }

        return map.get(head);
    }

    public static void main(String[] args) {
        Map<Integer,Integer> map = new HashMap<>();
        System.out.println(map.get(null));
    }
}
